package com.doit.day03;

import com.alibaba.fastjson.JSON;
import com.doit.day02.EventLog;
import org.apache.kafka.common.Cluster;

import java.util.Map;

public class MyPartitioner implements org.apache.kafka.clients.producer.Partitioner{

    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        String s = value.toString();
        EventLog eventLog = JSON.parseObject(s, EventLog.class);
        if(eventLog.getGuid() % 3 == 0){
            return 0;
        }else if(eventLog.getGuid() % 3 == 1){
            return 1;
        }else {
            return 2;
        }
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
